//
//  ViewController.m
//  AgoraDemo
//
//  Created by apple on 15/9/9.
//  Copyright (c) 2015年 Agora. All rights reserved.
//

#import "ViewController.h"


//#import <GPUImage/GPUImage.h>

@interface ViewController ()



//@property (nonatomic, strong) GPUImageVideoCamera *videoCamera;



//Configuration
@property (nonatomic, assign) CGSize  videoSize;
@property (nonatomic, assign) NSUInteger expectedSourceVideoFrameRate;
@property (nonatomic, assign) NSUInteger averageBitRate;
@property (nonatomic, strong) NSString   *publishUrl;
@property (atomic, assign) BOOL canInputFrame;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    //Init Configuration
    self.videoSize = CGSizeMake(480, 640);
    self.expectedSourceVideoFrameRate = 20;
    self.averageBitRate = 600;
    //    self.publishUrl = @"rtmp://fso.dca.35320.betacdn.net/2035320/default/slk?a3898FrplE9oP47b&adbe-live-event=test";
    self.publishUrl = @"rtmp://push1.arenazb.hupu.com/test/slk";
    
    self.canInputFrame = NO;

    
    //[self setupGPUImage];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//- (void)setupGPUImage
//{
//    GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];//AVCaptureDevicePositionFront
//    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
//    videoCamera.frameRate = [self expectedSourceVideoFrameRate];
//    
//    GPUImageRGBFilter *filter = [[GPUImageRGBFilter alloc] init];
//    
//    CGRect bounds = [UIScreen mainScreen].bounds;
//    GPUImageView *filteredVideoView = [[GPUImageView alloc] initWithFrame:bounds];
//    
//    // Add the view somewhere so it's visible
//    //    [self.view addSubview:filteredVideoView];
//    [self.view insertSubview:filteredVideoView atIndex:0];
//    
//    [videoCamera addTarget:filter];
//    [filter addTarget:filteredVideoView];
//    
//    GPUImageRawDataOutput *rawDataOutput = [[GPUImageRawDataOutput alloc] initWithImageSize:[self videoSize] resultsInBGRAFormat:YES];
//    [filter addTarget:rawDataOutput];
//    __weak GPUImageRawDataOutput *weakOutput = rawDataOutput;
//    __weak typeof(self) wself = self;
//    [rawDataOutput setNewFrameAvailableBlock:^{
//        //        __strong GPUImageRawDataOutput *strongOutput = weakOutput;
//        //        __strong typeof(wself) strongSelf = wself;
//        [weakOutput lockFramebufferForReading];
//        GLubyte *outputBytes = [weakOutput rawBytesForImage];
//        NSInteger bytesPerRow = [weakOutput bytesPerRowInOutput];
//        CVPixelBufferRef pixelBuffer = NULL;
//        CVPixelBufferCreateWithBytes(kCFAllocatorDefault, [self videoSize].width, [self videoSize].height, kCVPixelFormatType_32BGRA, outputBytes, bytesPerRow, nil, nil, nil, &pixelBuffer);
//        [weakOutput unlockFramebufferAfterReading];
//        if(pixelBuffer == NULL) {
//            return ;
//        }
//        if(wself.canInputFrame)
//        {
//            //[wself.session inputPixelBuffer:pixelBuffer];
//        }
//        CVPixelBufferRelease(pixelBuffer);
//    }];
//    [videoCamera startCameraCapture];
//    
//    self.videoCamera = videoCamera;
//}

@end
